import React, {Component} from 'react';
import {Map} from 'immutable';
import _ from 'lodash';

class App extends Component {
  constructor (props) {
    super(props);
    this.state = {
      data: Map({times: 0})
    };
  }
  // handleAdd () {
  //   let data = _.cloneDeep(this.state.data);
  //   data.times = data.times + 1;
  //   this.setState({data});
  //   // 如果上面不错cloneDeep，下面打印的结果会是加1后的值
  //   console.log(this.state.data.times);
  // }
  handleAdd () {
    this.setState(({data}) => ({
      data: data.update('times', v => v + 1)
    }));
    console.log(this.state.data.get('times'));
  }
  render () {
    return (
      <div>
        <h2>App</h2>
        <button onClick={this.handleAdd.bind(this)}>点击</button>
      </div>
    )
  }
}

export default App;
